package com.example.demo111;

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;


@Component
@EnableScheduling
public class ScheduledTask {
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //cron = "0 0/5 15-17 * * *"
    @Scheduled( cron = "0 0/5 15-17 * * *")
    public void printCurrentTime() throws InterruptedException {
        System.out.println("=====输出时间=======");
        System.out.println(String.format("当前时间为："+dateFormat.format( new Date())));
    }
}
